#ifndef TABLEMODEL_H
#define TABLEMODEL_H

#include <QAbstractTableModel>
#include <QPair>
#include <QVector>
#include <QByteArray>
#include <QFile>

#include "viewmode.h"

class ILoadFilterCallback
{
public:
	virtual void AddData(const char *, unsigned int) = 0;
	virtual ~ILoadFilterCallback(){};
};


class ILoadFilter
{
public:
	virtual bool loadThisData(const char *, unsigned int) = 0;
	virtual void startLoad(ILoadFilterCallback*) = 0;
	virtual void finishLoad() = 0;
	virtual ~ILoadFilter() {};
};


class DPOTableModel : public QAbstractTableModel, public ILoadFilterCallback
{
    Q_OBJECT
public:
    DPOTableModel(QObject *parent=0);
    DPOTableModel(const QString & fileName, QObject *parent=0);

	bool load(const QString & fileName, int splitsize = -1);
	QString getFilename() const;

	void setLoadFilter(ILoadFilter *);

    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
//    Qt::ItemFlags flags(const QModelIndex &index) const;

	// ILoadFilterCallback impl
	virtual void AddData(const char *, unsigned int);

public slots:
	void reset(ViewMode vm);

private:
	void clear();
private:
    QString _fileName;
	mutable QFile _file;
	struct DataItem
	{
		qint64 pos;
		int size;
//		bool readed;
		QByteArray ba;
	};
	mutable QVector< DataItem > _data;
	unsigned int _columnCount;
	ILoadFilter * _LoadFilter;
};

#endif
